package com.lc.demo.mapper;

import com.lc.demo.bean.Score;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ScoreMapper {


    @Update("update score set status =1 ,review=#{review},scorereview=#{scorereview} where id =#{id}")
    void review(Score score);
    @Select("select * from score where  username=#{username} and status=2 ")
    List<Score> selectScoreListByUsernameAndStatus2(String username);

    /*@Select({
            "<script> " +
                    "select * " +
                    "from score  " +
                    "where status in (0,2) " +
                    "<if test = 'username != null and username != \"\" '> " +
                    "and username = #{username}" +
                    "</if>" +
                    "<if test = 'subname != null and subname != \"\" '> " +
                    "and subname = #{subname}" +
                    "</if>" +
                    "<if test = 'term != null and term != \"\" '> " +
                    "and term = #{term}" +
                    "</if>" +
                    "</script>"
    })*/
    @Select("select  *  from score order by id desc")
    List<Score> findScoreList(Score score);
    @Update("update score set status =#{status} ,review=#{review} where id =#{id}")
    void adminReview(Score score);
    /*@Select({
            "<script> " +
                    "select * " +
                    "from score  " +
                    "where 1=1 " +
                    "<if test = 'username != null and username != \"\" '> " +
                    "and username = #{username}" +
                    "</if>" +
                    "<if test = 'subname != null and subname != \"\" '> " +
                    "and subname = #{subname}" +
                    "</if>" +
                    "<if test = 'term != null and term != \"\" '> " +
                    "and term = #{term}" +
                    "</if>" +
                    "</script>"
    })*/
    @Select("select  t2.* from `subject` t1, score t2 where t1.id=t2.subId and t1.teacherId=#{teacherId}")
    List<Score> findScoreListTeacher(@Param("teacherId") Integer teacherId);

    @Insert("insert into  score (username,subname,subId,score,status) values (#{username},#{subname},#{subId},#{score},0)")
    void addScore(Score score);

    @Delete("delete from score where id=#{id}")
    void delScoreById(Score score);

    @Select("select * from score where id=#{id}")
    Score getScoreById(Score score);
    @Update("update score set status =#{status} ,review=#{review} where id =#{id}")
    void teacherReview(Score score);

    @Update("update score set score=#{score},status=0 where id =#{id}")
    void updateScore(Score score);

    @Select("select t2.* from subject t1, score t2 where t1.id=t2.subId and t1.departmentid=#{departmentid}")
    List<Score> findScoreListBydepartmentid(@Param("departmentid") Integer departmentid);
}
